package com.haoyi.json.transfer;

import java.util.ArrayList;
import java.util.List;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;

/**
 * (1)maven依赖
	<dependency>
	            <groupId>com.alibaba</groupId>
	            <artifactId>fastjson</artifactId>
	            <version>1.1.22</version>
	</dependency>
 * @author sw-dinghongxu
 *
 */
public class FastJsonTest {
	
	public static void main(String args[]){
		Book book = new Book();
		book.setId("1");
		book.setName("钢铁是怎样炼成的");
		String jsonStr = JSON.toJSON(book).toString();
		
		System.out.println(jsonStr);
		
		String json = "[{\"id\":\"1\",\"name\":\"Json技术\"},{\"id\":\"2\",\"name\":\"java技术\"}]";
		List<Book> list = JSON.parseObject(json,new TypeReference<ArrayList<Book>>(){});
		
		for(Book bookSub : list){
			System.out.println(bookSub.getName());
		}
	}

}
